home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / bsrc_250.zip / ZRECEIVE.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  40KB  |  1,093 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*                      Zmodem file reception module                        */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*    For complete  details  of the licensing restrictions, please refer    */
  17. /*    to the License  agreement,  which  is published in its entirety in    */
  18. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  19. /*                                                                          */
  20. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  21. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  22. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  23. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  24. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  25. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  26. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  27. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  28. /*                                                                          */
  29. /*                                                                          */
  30. /* You can contact Bit Bucket Software Co. at any one of the following      */
  31. /* addresses:                                                               */
  32. /*                                                                          */
  33. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  34. /* P.O. Box 460398                AlterNet 7:491/0                          */
  35. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  36. /*                                Internet f491.n343.z1.fidonet.org         */
  37. /*                                                                          */
  38. /* Please feel free to contact us at any time to share your comments about  */
  39. /* our software and/or licensing policies.                                  */
  40. /*                                                                          */
  41. /*                                                                          */
  42. /*  This module is based largely on a similar module in OPUS-CBCS V1.03b.   */
  43. /*  The original work is (C) Copyright 1986, Wynn Wagner III. The original  */
  44. /*  authors have graciously allowed us to use their code in this work.      */
  45. /*                                                                          */
  46. /*--------------------------------------------------------------------------*/
  47.  
  48. /* Include this file before any other includes or defines! */
  49.  
  50. #include "includes.h"
  51.  
  52. /*--------------------------------------------------------------------------*/
  53. /* Local routines                                                           */
  54. /*--------------------------------------------------------------------------*/
  55.  
  56. int RZ_ReceiveData (byte *, int);
  57. int RZ_32ReceiveData (byte *, int);
  58. int RZ_InitReceiver (void);
  59. int RZ_ReceiveBatch (FILE *);
  60. int RZ_ReceiveFile (FILE *);
  61. int RZ_GetHeader (void);
  62. int RZ_SaveToDisk (long *);
  63. void RZ_AckBibi (void);
  64.  
  65. /*--------------------------------------------------------------------------*/
  66. /* Private declarations                                                     */
  67. /*--------------------------------------------------------------------------*/
  68.  
  69. static long DiskAvail;
  70. static long filetime;
  71. static char realname[64];
  72.  
  73. /*--------------------------------------------------------------------------*/
  74. /* Private data                                                             */
  75. /*--------------------------------------------------------------------------*/
  76.  
  77. /* Parameters for ZSINIT frame */
  78. #define ZATTNLEN 32
  79.  
  80. static char Attn[ZATTNLEN + 1];                  /* String rx sends to tx on
  81.                                                   * err            */
  82. static FILE *Outfile;                            /* Handle of file being
  83.                                                   * received           */
  84. static int Tryzhdrtype;                          /* Hdr type to send for Last
  85.                                                   * rx close      */
  86. static char isBinary;                            /* Current file is binary
  87.                                                   * mode             */
  88. static char EOFseen;                             /* indicates cpm eof (^Z)
  89.                                                   * was received     */
  90. static char Zconv;                               /* ZMODEM file conversion
  91.                                                   * request          */
  92. static int RxCount;                              /* Count of data bytes
  93.                                                   * received            */
  94. static char Upload_path[PATHLEN];                /* Dest. path of file being
  95.                                                   * received   */
  96. static long Filestart;                           /* File offset we started
  97.                                                   * this xfer from   */
  98.  
  99. /*--------------------------------------------------------------------------*/
  100. /* GET ZMODEM                                                               */
  101. /* Receive a batch of files.                                                */
  102. /* returns TRUE (1) for good xfer, FALSE (0) for bad                        */
  103. /* can be called from f_upload or to get mail from a WaZOO Opus             */
  104. /*--------------------------------------------------------------------------*/
  105. int get_Zmodem (char *rcvpath, FILE *xferinfo)
  106. {
  107.    char namebuf[PATHLEN];
  108.    int i;
  109.    char *p;
  110.    char *HoldName;
  111.    long t;
  112.  
  113. #ifdef DEBUG
  114.    show_debug_name ("get_Zmodem");
  115. #endif
  116.  
  117.    filetime = 0;
  118.  
  119.    IN_XON_ENABLE ();
  120.  
  121. /*   Secbuf = NULL;*/
  122.    Outfile = NULL;
  123.    z_size = 0;
  124.  
  125.  
  126.    Rxtimeout = 100;
  127.    Tryzhdrtype = ZRINIT;
  128.  
  129.    (void) strcpy (namebuf, rcvpath);
  130.    Filename = namebuf;
  131.  
  132.    (void) strcpy (Upload_path, rcvpath);
  133.    p = Upload_path + strlen (Upload_path) - 1;
  134.    while (p >= Upload_path && *p != '\\')
  135.       --p;
  136.    *(++p) = '\0';
  137.  
  138.    HoldName = HoldAreaNameMunge(&called_addr);
  139.  
  140.    (void) sprintf (Abortlog_name, "%s%s.Z\0",
  141.             HoldName, Hex_Addr_Str (&remote_addr));
  142.  
  143.    DiskAvail = zfree (Upload_path);
  144.  
  145.    if (((i = RZ_InitReceiver ()) == ZCOMPL) ||
  146.        ((i == ZFILE) && ((RZ_ReceiveBatch (xferinfo)) == OK)))
  147.       {
  148.       XON_DISABLE ();
  149.       XON_ENABLE ();                             /* Make sure xmitter is
  150.                                                   * unstuck */
  151.       return 1;
  152.       }
  153.  
  154.    CLEAR_OUTBOUND ();
  155.    XON_DISABLE ();                               /* Make sure xmitter is
  156.                                                   * unstuck */
  157.    send_can ();                                  /* transmit at least 10 cans    */
  158.    t = timerset (200);                           /* wait no more than 2
  159.                                                   * seconds  */
  160.    while (!timeup (t) && !OUT_